package com.ruoyi.security.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.security.domain.AfExtinguisher;
import com.ruoyi.security.service.IAfExtinguisherService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 灭火器台账Controller
 *
 * @author felix
 * @date 2022-02-28
 */
@Api(tags = " 灭火器台账")
@RestController
@RequestMapping("/afExtinguisher")
public class AfExtinguisherController extends BaseController {
    @Autowired
    private IAfExtinguisherService afExtinguisherService;

    /**
     * 查询灭火器台账列表
     */
    @ApiOperation(value="查询灭火器台账列表", notes="查询灭火器台账列表")
    @PreAuthorize(hasPermi = "security:afExtinguisher:list")
    @GetMapping("/list")
    public TableDataInfo list(AfExtinguisher afExtinguisher) {
        startPage();
        List<AfExtinguisher> list = afExtinguisherService.selectAfExtinguisherList(afExtinguisher);
        return getDataTable(list);
    }

    /**
     * 导出灭火器台账列表
     */
    @ApiOperation(value="导出灭火器台账列表", notes="导出灭火器台账列表")
    @PreAuthorize(hasPermi = "security:afExtinguisher:export")
    @Log(title = "灭火器台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AfExtinguisher afExtinguisher) throws IOException {
        List<AfExtinguisher> list = afExtinguisherService.selectAfExtinguisherList(afExtinguisher);
        ExcelUtil<AfExtinguisher> util = new ExcelUtil<AfExtinguisher>(AfExtinguisher.class);
        util.exportExcel(response, list, "灭火器台账数据");
    }
    /**
     * 获取灭火器台账详细信息
     */
    @ApiOperation(value="获取灭火器台账详细信息", notes="获取灭火器台账详细信息")
    @PreAuthorize(hasPermi = "security:afExtinguisher:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(afExtinguisherService.selectAfExtinguisherById(id));
    }

    /**
     * 新增灭火器台账
     */
    @ApiOperation(value="新增灭火器台账", notes="新增灭火器台账")
    @PreAuthorize(hasPermi = "security:afExtinguisher:add")
    @Log(title = "灭火器台账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AfExtinguisher afExtinguisher) {
        return toAjax(afExtinguisherService.insertAfExtinguisher(afExtinguisher));
    }

    /**
     * 修改灭火器台账
     */
    @ApiOperation(value="修改灭火器台账", notes="修改灭火器台账")
    @PreAuthorize(hasPermi = "security:afExtinguisher:edit")
    @Log(title = "灭火器台账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AfExtinguisher afExtinguisher) {
        return toAjax(afExtinguisherService.updateAfExtinguisher(afExtinguisher));
    }

    /**
     * 删除灭火器台账
     */
    @ApiOperation(value="删除灭火器台账", notes="删除灭火器台账")
    @ApiImplicitParam(name = "ids", value = "灭火器台账ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "security:afExtinguisher:remove")
    @Log(title = "灭火器台账", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(afExtinguisherService.deleteAfExtinguisherByIds(ids));
    }
}
